package com.example.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration //声明当前这个类为一个配置类
public class MybatisPlusConfig {

    @Bean //创建分页对象
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //创建一个拦截器对象
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //创建一个分页拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        //设置溢出总页数后是否进行处理
        paginationInnerInterceptor.setOverflow(true);
        //设置分页拦截器所操作的数据库类型
        paginationInnerInterceptor.setDbType(DbType.MYSQL);
        //将分页的拦截器添加到框架的拦截器中
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}
